/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package mnstudent.businessLayer;

import mnstudent.dataacesslayer.RegistrationCoursesDAL;
import mnstudent.datatranferobject.DetailedRegistrationCoursesDTO;
import mnstudent.datatranferobject.RegistrationCoursesDTO;
import mnstudent.datatranferobject.SubjectDisplay;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author 11520_000
 */
public class RegistrationCoursesBLL {
    
    private RegistrationCoursesDAL m_RegistrationCoursesDAL;
    
    public RegistrationCoursesBLL()
    {
        m_RegistrationCoursesDAL = new RegistrationCoursesDAL();
    }
    
    
      /**
     * Ham lay tat ca cac khoa
     *
     * @return ResultSet
     */
    public ResultSet getAllRegistrationCourses(){
        
        return m_RegistrationCoursesDAL.getAllRegistrationCourses();
    }
    public ResultSet getAllSubjectDisplayByMajorID(String _idMajor)
    {
        return m_RegistrationCoursesDAL.getAllSubjectDisplayByMajorID(_idMajor);
    }
    
    /**
     * Phuong thuc lay id cua phieu dk neu co theo mssv, ma hoc ky, ma nam hoc
     * @param _idStudent
     * @param _idSemester
     * @param _idYear
     * @return 
     */
    public String getIdOfRegistrationCoursesByStudentIdAndSemesterIDYearId(String _idStudent, String _idSemester, String _idYear)
    {
       return m_RegistrationCoursesDAL.getIdOfRegistrationCoursesByStudentIdAndSemesterIDYearId(_idStudent, _idSemester, _idYear);
    }
   
    /**
     * Phuong thuc lay danh sach cac mon hoc mo trong ky, nam hoc va theo nganh sinh vien
     * @param _idSemester
     * @param _idYear
     * @param _idMajor
     * @return 
     */
    public ResultSet getAllSubjectDisplayOpenBySemesterIDYearIDMajorID(String _idSemester, String _idYear, String _idMajor)
    {
        return m_RegistrationCoursesDAL.getAllSubjectDisplayOpenBySemesterIDYearIDMajorID(_idSemester, _idYear, _idMajor);
    }
    
    public int getMoneyOfCreditByNameKindOfSubject(String _nameKindOfSubject)
    {
        int temp = 0;
        ResultSet rs = m_RegistrationCoursesDAL.getMoneyOfCreditByNameKindOfSubject(_nameKindOfSubject);
        try {
            while(rs.next())
            {
                temp = rs.getInt(1);
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return temp;
    }
    /**
     * Phuong thuc lay len diem so lan sau cung cua mon hoc ma sinh vien da hoc
     * @param _idStudent
     * @param _idSubject
     * @return 
     */
    public float getAfterScoresSubjectOfStudentByStudentId(String _idStudent, String _idSubject)
    {
         float temp = -1;
         ResultSet rs = m_RegistrationCoursesDAL.getAfterScoresSubjectOfStudentByStudentId(_idStudent, _idSubject);
        try {
            while(rs.next())
            {
                temp = rs.getFloat(1);
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
         return temp;
    }
    /**
     * Ham lay khoa theo ma khoa
     * @param _id
     * @return tra ve table chon
     */
    public ResultSet getRegistrationCoursesById(String _id)
    {
       
        return m_RegistrationCoursesDAL.getRegistrationCoursesById(_id);
    }
    /**
     * Ham lay khoa theo ma khoa
     * @param _id
     * @return tra ve table chon
     */
    public ResultSet getRegistrationCoursesByStudentId(String _idStudent)
    {
        
        return m_RegistrationCoursesDAL.getRegistrationCoursesByStudentId(_idStudent);
    }
    
    public ArrayList<SubjectDisplay> getListSubjectDisplayRegistrationCoursesBySutdentId(String _idStudent, String _idSemester, String _idYear)
    {
        ArrayList<SubjectDisplay> temp = new ArrayList<>();
        String idRegistrationCourses = m_RegistrationCoursesDAL.getIdOfRegistrationCoursesByStudentIdAndSemesterIDYearId(_idStudent, 
                _idSemester, _idYear);
        ResultSet rsDetailedRegistrationCourses = m_RegistrationCoursesDAL.getAllDetailedRegistrationCoursesByIdFromDatabase(idRegistrationCourses);
        try {
            while(rsDetailedRegistrationCourses.next()){
                String idSubject = rsDetailedRegistrationCourses.getNString(2);
                ResultSet rsSubjectDisplayRegitration = m_RegistrationCoursesDAL.getSubjectDisplayRegitrationBySubjectIdFromDatabase(idSubject);
                while(rsSubjectDisplayRegitration.next())
                {
                    SubjectDisplay obj = new SubjectDisplay(rsSubjectDisplayRegitration.getNString(1),
                            rsSubjectDisplayRegitration.getNString(2),
                            rsSubjectDisplayRegitration.getNString(3),
                            rsSubjectDisplayRegitration.getInt(4));
                    temp.add(obj);
                }
            }
        } catch (SQLException ex) {
           ex.printStackTrace();
        }
        return temp;
    }
    /**
     * Phuong thuc lay ID lon nhat cua phieu dk
     * @return 
     */
    public ResultSet getIDegistrationCourses() {
        
        return m_RegistrationCoursesDAL.getIDegistrationCoursesFromDatabase();
    }
    
     /**
     * Phuong thuc lay ID lon nhat cua phieu dk
     * @return 
     */
    public String getIDegistrationCoursesToString()
    {
        String temp = "";
        ResultSet rs = getIDegistrationCourses();
        try {
            while(rs.next())
            {
                temp = rs.getNString(1);
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return temp;
    }
            
    public boolean insertRegistrationCoursesToDatabase(RegistrationCoursesDTO _registrationCourses)
    {
         return m_RegistrationCoursesDAL.insertRegistrationCoursesToDatabase(_registrationCourses);
    }
     /**
     * Phuong thuc insert danh sach chi tiet phieu dk xuogn database
     * @param _arrDetailedRegistration
     * @return 
     */
    public boolean insertListSubjectRegistrationToDetailedRegistration(ArrayList<DetailedRegistrationCoursesDTO> _arrDetailedRegistration)
    {
       return m_RegistrationCoursesDAL.insertListSubjectRegistrationToDetailedRegistration(_arrDetailedRegistration);
    }
    /**
     * Phuong thuc insert chi tiet phieu dk xuogn database
     * @param obj
     * @return 
     */
    public boolean insertDetailedRegistrationToDatabase(DetailedRegistrationCoursesDTO obj)
    {
        return m_RegistrationCoursesDAL.insertDetailedRegistrationToDatabase(obj);
    }
    
    /**
     * Ham cap nhat sua doi thong tin khoa
     * @param _registrationCourses
     * @return tue: thanh cong, false: that bai
     */
    public boolean updateRegistrationCoursesByIdToDatabase(RegistrationCoursesDTO _registrationCourses)
    {
        return m_RegistrationCoursesDAL.updateRegistrationCoursesByIdToDatabase(_registrationCourses);
    }
     /**
     * Ham cap nhat sua doi thong tin khoa
     * @param _registrationCourses
     * @return tue: thanh cong, false: that bai
     */
    public boolean deleteRegistrationCoursesByIdToDatabase(String _idRegistrationCourses)
    {
        return m_RegistrationCoursesDAL.deleteRegistrationCoursesByIdToDatabase(_idRegistrationCourses);
    }
    
    public boolean deleteRegistrationCoursesByStudentIdToDatabase(String _idStudent)
    {
        return m_RegistrationCoursesDAL.deleteRegistrationCoursesByStudentIdToDatabase(_idStudent);
    }
    
     public boolean deleteListDetailedRegistrationToDatabase(String _idRegistration)
    {
       return m_RegistrationCoursesDAL.deleteListDetailedRegistrationToDatabase(_idRegistration);
    }
    //</editor-fold>
}
